package com.kaishengit.action;

import java.util.List;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.kaishengit.pojo.Company;
import com.kaishengit.pojo.Contact;
import com.kaishengit.service.ContactService;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("/contact")
public class ContactAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<Contact> contactList; 
	private List<Company> companyList;
	private ContactService contactService; 
	private int size;
	private Contact contact;
	
	@Action("list")
	public String execute(){
		contactList =  contactService.findAllContacts();
		companyList = contactService.findAllCompany();
		size = companyList.size() + contactList.size();
		return SUCCESS;
	}
	
	@Action("newContact")
	public String newContact() {
		return SUCCESS;
	}
	
	@Action("newCompany")
	public String newCompany() {
		return SUCCESS;
	}

	@Action(value="saveContact",results={
			@Result(name=SUCCESS,type="redirectAction",params={"actionName","list"})
			})
	
	public String saveContact(){
		contactService.saveContact(contact);
		return SUCCESS;
	}
	//get  set 
	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	
	public List<Contact> getContactList() {
		return contactList;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public List<Company> getCompanyList() {
		return companyList;
	}

	public void setCompanyList(List<Company> companyList) {
		this.companyList = companyList;
	}

	public void setContactList(List<Contact> contactList) {
		this.contactList = contactList;
	}


	public ContactService getContactService() {
		return contactService;
	}

	@Autowired
	public void setContactService(ContactService contactService) {
		this.contactService = contactService;
	}
	
}
